import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Function;
import java.util.function.IntFunction;

public class Ffghj {
    public static void main(String[] args) {
        //1.filter方法
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张无忌-19","fyg-8","周韵穿-89","复印听-34");
        list.stream().map(new Function<String, Object>() {
            @Override
            public Object apply(String s) {
                String[] arr=s.split("-");
                String ageString=arr[1];
                int age =Integer.parseInt(ageString);
                return age;
            }
        }).forEach(s-> System.out.println(s));

        list.stream()
                .map(s->Integer.parseInt(s.split("-")[1]))
                .forEach(s-> System.out.println(s));


        long count = list.stream().count();
        System.out.println(count);

        //toArray()
        //不指定数据类型
        Object[] objects = list.stream().toArray();
        System.out.println(Arrays.toString(objects));

        //指定数组类型
        //apply的形参：流中数据的个数，要跟数组长度保持一致
        //apply的返回值：具体类型的数组
        String[] arg=list.stream().toArray(new IntFunction <String[]>() {
            @Override
            public String[] apply(int value) {
                return new String[value];
            }
        });
        System.out.println(Arrays.toString(arg));

        //简化
        String[] arr2=list.stream().toArray(value -> new String[value]);
        System.out.println(Arrays.toString(arr2));

    }

}
